<template>
    <DocumentUpload v-if="status === 0" @success="upLoadSuccess" />
    <DocumentParsing v-else :pdf-file="pdfFile" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import DocumentUpload from './DocumentUpload.vue'
import DocumentParsing from './DocumentParsing.vue';
import type { PdfFile } from '@/api/type';
import { useRouter } from 'vue-router'
const router = useRouter()

const status = ref<number>(0) // 0 在初始上传页面(if文件符合上传标准)=> 1 文件解析(把文件上传给后端接口)+聊天页面
// 把文件上传给后端接口
const pdfFile = ref<PdfFile>({ name: '', url: '', paperId: '', size: '' })
const upLoadSuccess = (data: any) => {
    console.log('data', data, pdfFile.value)
    if (data.data.file_url) {
        // status.value = 1
        pdfFile.value.url = data.data.file_url
        pdfFile.value.name = data.data.file_name
        pdfFile.value.paperId = data.data.paper_id
        pdfFile.value.size = data.data.file_size
        router.push({
            path: `/chat/documentParsing/`,
            query: JSON.parse(JSON.stringify(pdfFile.value))
        })
    }
}
</script>